import 'package:dio/dio.dart';

class ApiServer {
  static final ApiServer _instance = ApiServer._internal();
  factory ApiServer() {
    return _instance;
  }
  ApiServer._internal();
  static const _address = 'http://10.42.0.1:8000/api';

  final Dio _dio = Dio(
    BaseOptions(baseUrl: _address, connectTimeout: const Duration(seconds: 5)),
  );

  Future<Map<String, dynamic>?> addWifi({
    required String ssid,
    required String bssid,
    required String password,
  }) async {
    final response = await _dio.post(
      '/network/saved_wifi',
      data: {'ssid': ssid, 'bssid': bssid, 'password': password},
    );
    print(response);
    if (response.statusCode == 200) {
      return response.data['data'];
    } else {
      return null;
    }
  }

  Future<List?> getAllSavedWifi() async {
    final response = await _dio.get('/network/saved_wifi/list');
    print(response);
    if (response.statusCode == 200) {
      return response.data['data'];
    } else {
      return null;
    }
  }

  Future<bool> connectWifi(String uuid) async {
    final response = await _dio.get('/network/saved_wifi/connect');
    print(response);
    if (response.statusCode == 200) {
      return true;
    } else {
      return false;
    }
  }
}
